$(document).ready(function(){
	
	$('#top').bind("click",function(){
//		location.href =  location.protocol + "//" + location.host +"/" + contextPath;
		location.href = MECHOICE.Utils.homePage();
	});
	
	/* MENU START */
	$('.hoverTitle').each(function(){
		var titleName = $(this).text();
		$(this).text("");
		$(this).append(MECHOICE.CONS.GET('MENU_HTML'));
		$(this).find('.head_menu_normal_center').text(titleName);		   
	});
	
	$('.hoverTitle').bind("mouseover",function(){
		var divArr = $(this).find("DIV");
		
		$(divArr.get(0)).removeClass("head_menu_normal_left");
		$(divArr.get(1)).removeClass("head_menu_normal_center");
		$(divArr.get(2)).removeClass("head_menu_normal_right");
		
		$(divArr.get(0)).addClass("head_menu_hover_left");
		$(divArr.get(1)).addClass("head_menu_hover_center");
		$(divArr.get(2)).addClass("head\_menu_hover_right");
	});
	
	$('.hoverTitle').bind("mouseout",function(){
		var divArr = $(this).find("DIV");
		
		$(divArr.get(0)).removeClass("head_menu_hover_left");
		$(divArr.get(1)).removeClass("head_menu_hover_center");
		$(divArr.get(2)).removeClass("head_menu_hover_right");
		
		$(divArr.get(0)).addClass("head_menu_normal_left");
		$(divArr.get(1)).addClass("head_menu_normal_center");
		$(divArr.get(2)).addClass("head_menu_normal_right");
		
	});
	
	$('.hoverTitle_selected').each(function(){
		var titleName = $(this).text();
		$(this).text("");
		$(this).append(MECHOICE.CONS.GET('MENU_SELECTED_HTML'));
		$(this).find('.head_menu_hover_center').text(titleName);		   
	});
	
	
	/* MENU END */
	
	/* PAGER START */
	
	$('.pager_block').each(function(){
		//var curr_pager = $($(this).find("DIV").get(0));		
		var aHtml = $(this).html();
		var pageNum = $(aHtml).text();
		var _href = $(aHtml).attr("href");
		$(this).attr("href",_href);
		$(this).html("");
		$(this).append(MECHOICE.CONS.GET('PAGER_NORMAL_HTML'));
		$(this).find('.pager_center').html(pageNum);	
		$(this).find('.pager_left').html("");
		$(this).find('.pager_right').html("");
	});
	
	$('.pager_block').bind("click",function(){
		window.location.href = $(this).attr("href");
	});
	
	$('.pager_block').bind("mouseover",function(){
		var divArr = $(this).find("DIV");
		if( !$(this).find('.pager_center_selected').text() ){
			$(divArr.get(0)).removeClass("pager_left");
			$(divArr.get(1)).removeClass("pager_center");
			$(divArr.get(2)).removeClass("pager_right");
			
			$(divArr.get(0)).addClass("pager_left_hover");
			$(divArr.get(1)).addClass("pager_center_hover");
			$(divArr.get(2)).addClass("pager_right_hover");
		}
		
	});
	
	$('.pager_block').bind("mouseout",function(){
		var divArr = $(this).find("DIV");
		if( !$(this).find('.pager_center_selected').text() ){
			$(divArr.get(0)).removeClass("pager_left_hover");
			$(divArr.get(1)).removeClass("pager_center_hover");
			$(divArr.get(2)).removeClass("pager_right_hover");
			
			$(divArr.get(0)).addClass("pager_left");
			$(divArr.get(1)).addClass("pager_center");
			$(divArr.get(2)).addClass("pager_right");
		}
		
	});
	
	$('.pager_selected').each(function(){
		//var curr_pager = $($(this).find("DIV").get(0));		
		var titleName = $(this).text();
		$(this).text("");
		$(this).append(MECHOICE.CONS.GET('PAGER_SELECTED_HTML'));
		$(this).find('.pager_center_selected').text(titleName);		   
	});
	
	
	/* PAGER END */
	
	/* SEARCH AREA START */
	
	$('.search_area').each(function(){
		var searchHtml = $(this).html();
		$(this).html("");
		$(this).append(MECHOICE.CONS.GET('SEARCH_HTML'));
		$(this).find('.search_area_center').prepend(searchHtml);
	});
	
	$('img[search_ico]').bind("mouseover",function(){
		$(this).attr("src",contextPath +"/skin/light_blue/images/search_icon_hover.png");
	});
	
	$('img[search_ico]').bind("mouseout",function(){
		$(this).attr("src",contextPath +"/skin/light_blue/images/search_icon.png");
	});
	
	$('img[search_ico]').bind("mousedown",function(){
		$(this).attr("src", contextPath +"/skin/light_blue/images/search_icon_click.png");
	});
	
	$('img[search_ico]').bind("mouseup",function(){
		$(this).attr("src", contextPath +"/skin/light_blue/images/search_icon.png");
	});
	
	/* SEARCH AREA END */
	
	/* SEARCH INPUT START */
	$('#search_text').val(MECHOICE.CONS.GET('SEARCH_TXT'));
	$('#search_text').addClass("search_font_init");

	$('#search_text').bind("click",function(){
		if( $(this).val() === MECHOICE.CONS.GET('SEARCH_TXT') ){
			$(this).val("");
			$(this).removeClass("search_font_init");
			$(this).addClass("search_font_input");
		}
	});
	
	$('#search_text').bind("blur",function(){
		if( $.trim($(this).val()) === "" ){
			$(this).val(MECHOICE.CONS.GET('SEARCH_TXT'));
			$(this).removeClass("search_font_input");
			$(this).addClass("search_font_init");
		}
	});
	
	/* SEARCH INPUT END */
	
	/* sidebar START */
	$('.sidebar_title').each(function(){
		var titleName = $(this).text();
		$(this).text("");
		$(this).append(MECHOICE.CONS.GET('SIDEBAR_TITLE_HTML'));
		$(this).find('.sidebar_title_center').text(titleName);								  
	});
	
	/* sidebar END */
	
	/* content START */
	$('.content_title').each(function(){
		var titleName = $(this).html();
		$(this).html("");
		$(this).append(MECHOICE.CONS.GET('CONTENT_TITLE_HTML'));
		$(this).find('.content_title_center').html(titleName);								  
	});
	
	/* content END */
	
	/* footer content START */
	$('.footer_content').each(function(){
		var footerHtml = $(this).html();
		$(this).html("");
		$(this).append(MECHOICE.CONS.GET('FOOTER_CONTENT_HTML'));
		$(this).find('.footer_center').prepend(footerHtml);						  
	});
	/* footer content END */
	
});

window.MECHOICE = {
	"CONS" : (function(){
		var SEARCH_TXT = " 请输入内容搜索...";
		
		var MENU_HTML = "<div class=\"head_menu_normal_left\" ></div><div class=\"head_menu_normal_center\" ></div><div class=\"head_menu_normal_right\" ></div>";
		
		var MENU_SELECTED_HTML = "<div class=\"head_menu_hover_left\" ></div><div class=\"head_menu_hover_center\" ></div><div class=\"head_menu_hover_right\" ></div>";
		
		var SEARCH_HTML = "<div class=\"search_area_left\" ></div><div class=\"search_area_center\"><img src=\""+ contextPath +"/skin/light_blue/images/search_icon.png\" search_ico=\"search_ico\" /></div><div class=\"search_area_right\" ></div>";
		
		var SIDEBAR_TITLE_HTML = "<div class=\"sidebar_title_left\" ></div><div class=\"sidebar_title_center\" ></div><div class=\"sidebar_title_right\" ></div>";
		
		var CONTENT_TITLE_HTML = "<div class=\"content_title_left\" ></div><div class=\"content_title_center\" ></div><div class=\"content_title_right\" ></div>";
		
		var FOOTER_CONTENT_HTML = "<div class=\"footer_left\" ></div><div class=\"footer_center\" ></div><div class=\"footer_right\" ></div>";
		
		var PAGER_NORMAL_HTML = "<div class=\"pager_left\" ></div><div class=\"pager_center\" ></div><div class=\"pager_right\" ></div>";
		
		var PAGER_SELECTED_HTML = "<div class=\"pager_left_selected\" ></div><div class=\"pager_center_selected\" ></div><div class=\"pager_right_selected\" ></div>";
		
		var _CONSTANT = function(){};

		_CONSTANT.GET = function(name){
			try{
				return eval(name);
			}catch(e){
				return "";
			}
		};
		
		return _CONSTANT;
	})(),
	Utils : (function(){
		var _utils = function(){};
		_utils.homePage = function(){
			return location.protocol + "//" + location.host +"/" + contextPath;
		}
		
		return _utils;
	})()
};